#include <stdio.h>

const char * ps_no			= "no";
const char * ps_empty		= "";
const char * ps_doble_crlf	= "\r\n\r\n";
const char * ps_attr_content_type = "Content-Type";

const char * s_post_ej		=
	"POST /x HTTP/1.0\r\n"
	"From: frog@jmarshall.com\r\n"
	"User-Agent: HTTPTool/1.0\r\n"
	"Content-Type: application/x-www-form-urlencoded\r\n"
	"Content-Length: 32\r\n"
	"\r\n"
	"a=1&d=1"
;

size_t strlen_until_char (const char *str, char until_char)
{
	const char *s;
	for (s = str; *s != until_char; ++s)
		;
	return (s - str);
}

char * valor_atributo (const char *response, const char *atributo)
{
	char *ptr = strstr(response, atributo);
	while (*ptr != ':')	// como mientras no sea ':'
		ptr++;
	ptr++;				// como el ':'
	while (*ptr == ' ')	// como mientras no sea espacio
		ptr++;	
	return ptr;			// retorno el puntero al valor
}

void main (int argc, char ** argv)
{
	char *data;
	data = strstr(s_post_ej, ps_doble_crlf);
	data += 4; // como /r/n/r/n

	printf ("%s\n", s_post_ej);
	printf ("------------\n");
	printf ("%s\n", data  );
	printf ("------------\n");

	printf ("a %s existe\n", strstr(data, "a=") ? ps_empty : ps_no);
	printf ("b %s existe\n", strstr(data, "b=") ? ps_empty : ps_no);
	printf ("c %s existe\n", strstr(data, "c=") ? ps_empty : ps_no);
	printf ("d %s existe\n", strstr(data, "d=") ? ps_empty : ps_no);

	printf (">>>>%s<<<<\n", valor_atributo (s_post_ej, ps_attr_content_type));
	getchar();
}
